﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IOLx
{
    class Program
    {

        static void Main(string[] args)
        {
            //Driveinfo 获取计算机驱动器信息
            DriveInfo driveInfo = new DriveInfo("D");
            Console.WriteLine("驱动器的名称:"+driveInfo.Name);
            Console.WriteLine("驱动器类型:"+driveInfo.DriveType);
            Console.WriteLine("驱动器的文件格式:"+driveInfo.DriveFormat);
            Console.WriteLine("驱动器中可用空间大小:"+driveInfo.TotalFreeSpace);
            Console.WriteLine("驱动器总大小:"+driveInfo.TotalSize);

            Console.WriteLine();

            //Directoryinfo 文件夹操作 （需实例化）
            DirectoryInfo directoryinfo = new DirectoryInfo("D:\\code");
            directoryinfo.Create(); //创建文件夹
            directoryinfo.CreateSubdirectory("code-1");//创建子文件夹
            directoryinfo.CreateSubdirectory("code-2");

            //列出目录的文件夹
            IEnumerable<DirectoryInfo> dir = directoryinfo.EnumerateDirectories();
            foreach (var i in dir)
            {
                Console.WriteLine(i.Name);
            }

            //在一个子文件夹下创建一个文件夹
            DirectoryInfo directoryinfo1 = new DirectoryInfo("D:\\code\\code-1");
            directoryinfo1.Create();
            directoryinfo1.CreateSubdirectory("Word");

            //删除文件夹 删空文件夹需要Delete(true)
            directoryinfo.Delete(true);

            //Directory 文件夹操作 （静态类无需实例化）
            bool flag= Directory.Exists("D:\\code");
            Console.WriteLine(flag);
            if (flag)
            {
                Directory.Delete("D:\\code",true);
            }
            else
            {
                Directory.CreateDirectory("D:\\code");
            }
        }
    }
}
